$(document).ready(function () {
    changeCode();//生成验证码
    $("#codeImg").bind("click", changeCode);//验证码图片点击
    kickout();//判断会话过期提醒
    //addAnimate(); //图片动画效果
});

//图片动画效果
function addAnimate() {
    $curtainopen = false;
    $(".rope").click(function () {
        $(this).blur();
        if ($curtainopen == false) {
            $(this).stop().animate({
                top: '0px'
            }, {
                queue: false,
                duration: 350,
                easing: 'easeOutBounce'
            });
            $(".leftcurtain").stop().animate({
                width: '60px'
            }, 2000);
            $(".rightcurtain").stop().animate({
                width: '60px'
            }, 2000);
            $curtainopen = true;
        } else {
            $(this).stop().animate({
                top: '-40px'
            }, {
                queue: false,
                duration: 350,
                easing: 'easeOutBounce'
            });
            $(".leftcurtain").stop().animate({
                width: '50%'
            }, 2000);
            $(".rightcurtain").stop().animate({
                width: '51%'
            }, 2000);
            $curtainopen = false;
        }
        return false;
    });
}

//获取当前时间
function genTimestamp() {
    var time = new Date();
    return time.getTime();
}

//获取验证码
function changeCode() {
    $("#codeImg").attr("src", system + "/code/getSessioniCode?type=" + 3);
}

//登录
function login() {
    if (!$("#login").form('validate')) {//验证表单信息
        return;
    }
    var password = $("#password").val();
    if (password.length < 6) {
        $.messager.alert('系统提示', "密码错误，请重新输入！！", 'error');
        return;
    }
    var encryptpassword = new SM3().sm3encrypt(password);
    if ($("#login").form('validate')) {
        $.messager.progress({text: '正在登录中...',});
        $.ajax({
                type: "post",
                url: system + "/userlogin/loginExc",
                dataType: "json",
                data: {
                    loginId: $("#loginId").val(),
                    password: encryptpassword,
                    code: $("#code").val()
                },
                success: function (data) {
                    $.messager.progress('close');
                    if (successcode != data.code) {
                        //错误提示信息的方法
                        $.messager.alert('系统提示', data.message, 'error');
                        changeCode();//刷新验证码
                        $.messager.progress('close');
                        return;
                    }
                    window.location.href = system + "/main/main";//成功调整主页加载主页信息
                }, error: function (data) {
                    $.messager.progress('close');
                    $.messager.alert('系统提示', "系统异常，请稍后重试！", 'error');
                }
            }
        );
    }
}

//按下enter触发登录
$(document).keydown(function (e) {
    if (e.keyCode == 13) {
        if (!$("#login").form('validate')) {//验证表单信息
            return;
        }
        $("[name=loginBtn]").trigger("click");
    }
});

function register() {
    var content = "<iframe src=" + system + "/user/register width='100%' height='99%' frameborder='0' scrolling='no'></iframe>";
    $('#dlg').dialog({
        title: "用户注册",
        content: content,
    }).dialog('open');
}

function closeDlg(message) {
    if (!isNull(message)) {
        $.messager.show({title: '系统提示', msg: message});
    }
    $('#dlg').dialog('close');
}

